package com.lwf.fatapi.controller;

import com.lwf.fatapi.dto.LoginRequest;
import com.lwf.fatapi.service.AuthService;
import com.lwf.fatapi.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 认证控制器
 *
 * @author lwf
 */
@Tag(name = "认证管理", description = "用户认证相关接口")
@RestController
@RequestMapping("/auth")
public class AuthController {

    @Autowired
    private AuthService authService;

    @Operation(summary = "用户登录")
    @PostMapping("/login")
    public Result<Map<String, Object>> login(@RequestBody @Validated LoginRequest request) {
        Map<String, Object> result = authService.login(request);
        return Result.success("登录成功", result);
    }

    @Operation(summary = "用户登出")
    @PostMapping("/logout")
    public Result logout() {
        authService.logout();
        return Result.success("登出成功");
    }

    @Operation(summary = "获取当前用户信息")
    @GetMapping("/current")
    public Result<Map<String, Object>> getCurrentUser() {
        Map<String, Object> result = authService.getCurrentUser();
        return Result.success(result);
    }

    @Operation(summary = "刷新Token")
    @PostMapping("/refresh")
    public Result<Map<String, Object>> refreshToken() {
        Map<String, Object> result = authService.refreshToken();
        return Result.success("刷新成功", result);
    }
}
